<template>
    <div>
        ￥{{showPrice}}
    </div>
</template>
<script>
import {translateDetailData} from '@/utils/TranslateDetailDate'
import {
    queryCart,
    queryGoodsFoodListNormal,
    queryPromotionInfo,
    queryPromotionInfoOffLine,
    queryShoppingCartForCart,
    queryFoodCart,
    queryFoodCartForCart,
    deleteFoodCart,
    addFoodCart,
    updateFoodCart,
    FoodqueryPromotionInfo
  } from '@/utils/ReturnAxios';
import {mapMutations, mapGetters} from 'vuex';

export default {
    data(){
        return{
            ableList:[],
            showPrice:'0.00',
        }
    },
    computed:{
        // 获取购物车列表
        cartList() {
            return this.$store.state.lyj.activeCartList || []
        },
        ...mapGetters('wxh', [
            'sessionId',
            'login',
            'userInfo'
        ]),

    },
    watch:{
        cartList(data) {
            this.$nextTick(() => {
                this.ableList = data.filter((item) => {
                    var item = translateDetailData(item)
                    return item
                })
                this.timeOut && clearTimeout(this.timeOut)
                this.timeOut = setTimeout(
                    () => {
                        if (data.length > 0) {
                        this.queryRegularDetail()
                        } else {
                        this.showPrice = "0.00";
                        }
                    }, 100
                )
            })
        },
    },
    created() {
        this.queryRegularDetail()
        
    },
    methods:{
        //获取购物车的优惠信息
        async queryRegularDetail() {
            var res
            var sessionId = this.sessionId
            if (!sessionId) {
            var selectList = this.ableList
            if (selectList.length == 0) {
                return
            }
            var shoppingCartLists = selectList.map((item) => {
                return {
                goodsCode: item.goodsCode,
                goodsId: item.goodsId,
                goodsNum: item.goodsNum,
                preorder: item.preorder,
                goodsUnit:item.goodsunit,
                cartType:1
                }
            })
            var data = {shoppingCartLists}
            res = await  queryPromotionInfoOffLine(data)
            } else {
            var res = await FoodqueryPromotionInfo()
            }
            res = res.data
            if (res.returnCode == 1) {
                this.showPrice = res.data[0].totalMoney.toFixed(2);
            }


        },
    }
}
</script>
<style scoped>

</style>

